registerReceiver

@Nullable
open fun registerReceiver(@NonNull context: @NonNull Context, @Nullable receiver: @Nullable BroadcastReceiver, @NonNull filter: @NonNull IntentFilter, flags: Int): @Nullable Intent(source)

Register a broadcast receiver.

Return

The first sticky intent found that matches filter, or null if there are none.

Parameters

context

Context to retrieve service from.

receiver

The BroadcastReceiver to handle the broadcast.

filter

Selects the Intent broadcasts to be received.

flags

If this receiver is listening for broadcasts sent from other apps—even other apps that you own—use the RECEIVER_EXPORTED flag. If instead this receiver is listening only for broadcasts sent by your app, or from the system UID, use the RECEIVER_NOT_EXPORTED flag.

See also

https

://developer.android.com/develop/background-work/background-tasks/broadcasts#context-registered-receivers


@Nullable
open fun registerReceiver(@NonNull context: @NonNull Context, @Nullable receiver: @Nullable BroadcastReceiver, @NonNull filter: @NonNull IntentFilter, @Nullable broadcastPermission: @Nullable String, @Nullable scheduler: @Nullable Handler, flags: Int): @Nullable Intent(source)

Register a broadcast receiver.

Return

The first sticky intent found that matches filter, or null if there are none.

Parameters

context

Context to retrieve service from.

receiver

The BroadcastReceiver to handle the broadcast.

filter

Selects the Intent broadcasts to be received.

broadcastPermission

String naming a permission that a broadcaster must hold in order to send and Intent to you. If null, no permission is required.

scheduler

Handler identifying the thread will receive the Intent. If null, the main thread of the process will be used.

flags

If this receiver is listening for broadcasts sent from other apps—even other apps that you own—use the RECEIVER_EXPORTED flag. If instead this receiver is listening only for broadcasts sent by your app, or from the system UID, use the RECEIVER_NOT_EXPORTED flag.

See also

https

://developer.android.com/develop/background-work/background-tasks/broadcasts#context-registered-receivers